package com.cn.wanxi.service;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.model.NewsModel;

/**
 * 逻辑层就是写逻辑代码
 */
public class NewsService {
    public Object getNewsModels() {
        NewsDao newsDao = new NewsDao();
        int length = newsDao.contents.length;
        NewsModel[] newsModels = new NewsModel[length];
        for (int i = 0; i < length; i++) {
            NewsModel model = new NewsModel();
            model.setTitle(NewsDao.TITLES[i]);
            model.setContent(newsDao.contents[i]);
            newsModels[i] = model;
        }
        return newsModels;
    }

    /**
     * 封装新闻页面的新闻信息
     *
     * @return
     */
    public Object getNewsModelsForNewsPage() {
        NewsDao newsDao = new NewsDao();
        int length = newsDao.contentsForNewsPage.length;
        NewsModel[] newsModels = new NewsModel[length];
        for (int i = 0; i < length; i++) {
            NewsModel model = new NewsModel();
            model.setTitle(NewsDao.TITLES_FOR_NEWS_PAGE[i]);
            model.setContent(newsDao.contentsForNewsPage[i]);
            model.setReleaseTime(newsDao.releaseTimesForNewsPage[i]);
            newsModels[i] = model;
        }
        return newsModels;
    }
}
